//
//  BaseViewController.m
//  HiMaster3
//
//  Created by jinghao on 15/12/11.
//  Copyright © 2015年 jinghao. All rights reserved.
//

#import "BaseViewController.h"
#import "MasterTableHeaderView.h"
#import "MasterTableFooterView.h"
#import "LoadingFailView.h"
#import "TableViewModel.h"
#import "UINavigationBar+Awesome.h"
#import <MessageUI/MessageUI.h>

#define IOS8_OR_LATER [[UIDevice currentDevice].systemVersion floatValue]>=8.0
@interface BaseViewController ()<UINavigationControllerDelegate,UIGestureRecognizerDelegate,MFMessageComposeViewControllerDelegate,UIViewControllerTransitioningDelegate>
@property (nonatomic, assign)            NSInteger             count;
@property (nonatomic, assign)            BOOL                  canLock;
@property (nonatomic, strong)            UIScrollView        *freshScrollView;
@property (nonatomic, strong)            LoadingFailView     *loadingFailView;
@property (nonatomic, strong)            NSDictionary        * requestAlert;
@property (nonatomic, strong)            NSDictionary        * userInfo;
@property (nonatomic, strong)            NSString            * message;
@property (nonatomic, strong)            SendMessageView     * sendMessageView;
@property (nonatomic, strong)            ShareDataView       * shareDataView;
@property (nonatomic, strong)            YiAudioRecoder      * record;
@property (nonatomic, strong, readwrite) BaseViewModel       * viewModel;
@property (nonatomic, strong, readwrite) UserClient          * userClient;
@property (nonatomic, strong, readwrite) UITextField         * searchTitleView;
@end

@implementation BaseViewController

+ (instancetype)allocWithZone:(struct _NSZone *)zone {
    BaseViewController *viewController = [super allocWithZone:zone];
    
    @weakify(viewController)
    [[viewController
      rac_signalForSelector:@selector(viewDidLoad)]
     subscribeNext:^(id x) {
         @strongify(viewController)
         [viewController bindViewModel];
     }];
    return viewController;
}


- (void)viewDidLoad {
    [super viewDidLoad];
    self.automaticallyAdjustsScrollViewInsets = NO;
    UIBarButtonItem *backItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"BackNormal"] style:UIBarButtonItemStylePlain target:self action:@selector(gotoBack)];
    [self.navigationItem setLeftBarButtonItem:backItem];
//    [self.navigationController.navigationBar setHidden:YES];
//    [self setBackGroundImg];
    self.hiddenTabbar = YES;
    self.showLeftMenu =NO;
    self.urlManager = [MasterUrlManager shareMasterUrlManager];
    NSString *title = self.params[@"title"];
    if (title) {
        self.viewModel.title = title;
    }
}

//-(BouncePresentAnimation *)presentAnimation{
//    if(!_presentAnimation){
//        _presentAnimation = [BouncePresentAnimation new];
//    }
//    return _presentAnimation ;
//}
//-(SwipeUpInteractiveTransition *)transitionController{
//    if(!_transitionController){
//        _transitionController = [SwipeUpInteractiveTransition new];
//    }
//    return _transitionController ;
//}
//-(NormalDismissAnimation *)dismissAnimation{
//    if(!_dismissAnimation){
//        _dismissAnimation = [NormalDismissAnimation new];
//    }
//    return _dismissAnimation ;
//}

//-(void)pushToScene:(NSString *)storyName And:(NSString *)viewController{
//    if( [self doLogin]){
//        UIStoryboard *HelpStory = [UIStoryboard storyboardWithName:storyName bundle:[NSBundle mainBundle]];
//        BaseViewController * BaseViewController = [HelpStory instantiateViewControllerWithIdentifier:viewController];
//        BaseViewController.transitioningDelegate = self;
//        [self.transitionController wireToViewController:BaseViewController];
//        [self presentViewController:BaseViewController animated:YES completion:nil];
//    }
//}
- (void)showNavigationBar{
    self.navigationController.navigationBar.userInteractionEnabled = YES;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear: animated];
    self.navigationController.interactivePopGestureRecognizer.delegate = self;
    self.navigationController.interactivePopGestureRecognizer.enabled = YES;
//    NSLog(@"viewWillAppear %@  tabbar %d",self,self.tabBarController.tabBar.hidden);
    NSString *plistPath = [[NSBundle mainBundle] pathForResource:@"BehaviourStringList" ofType:@"plist"];
    NSMutableDictionary *behaviourStringdata = [[NSMutableDictionary alloc] initWithContentsOfFile:plistPath];
    NSString *className = [NSString stringWithFormat:@"%@",self.class];
    self.userClient.currentVC = className;
//    NSLog(@"%@",self.class);
    if (className == nil || [behaviourStringdata objectForKey:className] == nil) {
        return;
    }
    else{
    [self addUserBehaviourString:[behaviourStringdata objectForKey:className]];
    }
}

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    if (self.viewModel) {
        self.viewModel.active = YES;
    }
    [SlideNavigationController sharedInstance].enableSwipeGesture = YES;
}

- (BOOL)prefersStatusBarHidden{
    return NO;
}

//-(UIStatusBarStyle)preferredStatusBarStyle{
//    return UIStatusBarStyleLightContent;
//}

- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
//    NSLog(@"viewWillDisappear %@  tabbar %d",self,self.tabBarController.tabBar.hidden);

}

- (UserClient*)userClient
{
    if (!_userClient) {
        _userClient = [UserClient sharedUserClient];
    }
    return _userClient;
}

#pragma mark -- SlideNavigationControllerDelegate

//- (BOOL)slideNavigationControllerShouldDisplayLeftMenu
//{
//    return self.showLeftMenu;
//}


#pragma mark -- 私有方法
- (NSString*)getPathByFileNameWithType:(NSString *)_type
{
    NSString* fileDirectory = [[self getSavePath] stringByAppendingPathComponent:[[NSString stringWithFormat: @"%.0f", [NSDate timeIntervalSinceReferenceDate] * 1000.0] stringByAppendingPathExtension:_type]];
    return fileDirectory;
}
-(NSString *)getSavePath{
//    NSString *urlStr=[NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) lastObject];
    NSFileManager *fileManager = [[NSFileManager alloc] init];
    NSString *pathDocuments = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
    NSString *createPath = [NSString stringWithFormat:@"%@/Audio", pathDocuments];
    // 判断文件夹是否存在，如果不存在，则创建
    if (![[NSFileManager defaultManager] fileExistsAtPath:createPath]) {
        [fileManager createDirectoryAtPath:createPath withIntermediateDirectories:YES attributes:nil error:nil];
    }
    return createPath;
}

- (UITextField*)searchTitleView
{
    if (!_searchTitleView) {
        _searchTitleView = [[UITextField alloc] initWithFrame:CGRectMake(0, 0, 200, 25)];
        [_searchTitleView setBackgroundColor:[UIColor colorWithHex:0xd3d3d3]];
        [_searchTitleView setCornerRadius:4];
        _searchTitleView.font = [UIFont systemFontOfSize:13.0f];
        _searchTitleView.returnKeyType  = UIReturnKeySearch;
        _searchTitleView.enablesReturnKeyAutomatically = YES;
        UIImageView *leftView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Search_small_icon"]];
        _searchTitleView.leftView =leftView;
        _searchTitleView.leftViewMode = UITextFieldViewModeAlways;
        _searchTitleView.placeholder =@"可填写地址相关关键词";
        [_searchTitleView setValue:[UIColor whiteColor] forKeyPath:@"_placeholderLabel.textColor"];
        _searchTitleView.tintColor = [UIColor whiteColor];
        
    }
    return _searchTitleView;
}

/**
 *  返回
 *
 */
- (void)gotoBack{
    if ([self canGotoBack]) {
        [self.navigationController popViewControllerAnimated:YES];
        if(self.showLeftMenu){
//            [[SlideNavigationController sharedInstance] toggleLeftMenu];

        }
    }
}


- (void)gotoBack:(BOOL)animated viewControllerName:(NSString*)viewControllerName{
    
    if ([self canGotoBack]) {
        if (self.navigationController) {
            NSMutableArray* array = [NSMutableArray array];
            for (UIViewController* view in self.navigationController.childViewControllers) {
                NSString* className =  NSStringFromClass([view class]);
                [array addObject:view];
                if ([className isEqualToString:viewControllerName]) {
                    break;
                }
            }
            [self.navigationController setViewControllers:array animated:animated];
        }else{
            [self dismissViewControllerAnimated:animated completion:^{
                
            }];
        }
    }
}

- (void)pushViewControllerFrom:(NSString*)viewControllerName viewController:(UIViewController*)viewController animated:(BOOL)animated
{
    if (self.navigationController) {
        NSMutableArray* array = [NSMutableArray array];
        for (UIViewController* view in self.navigationController.childViewControllers) {
            NSString* className =  NSStringFromClass([view class]);
            [array addObject:view];
            if ([className isEqualToString:viewControllerName]) {
                break;
            }
        }
        [array addObject:viewController];
        [self.navigationController setViewControllers:array animated:animated];
    }else{
        [self presentViewController:viewController animated:animated completion:^{
            
        }];
    }
}

- (NSString*)backTitle{
    if (_backTitle==nil) {
        return @"返回";
    }
    return _backTitle;
}
- (BOOL)canGotoBack {
    return YES;
}

- (LoadingFailView*)loadingFailView{
    if (!_loadingFailView) {
        _loadingFailView = [[LoadingFailView alloc] init];
        _loadingFailView.hidden = TRUE;
        [self.view addSubview:_loadingFailView];
        [_loadingFailView mas_makeConstraints:^(MASConstraintMaker *make) {
           make.edges.equalTo(self.view).with.insets(UIEdgeInsetsMake(0, 0, 0, 0));
        }];
    }
    return _loadingFailView;
}

//- (void)setTitle:(NSString *)title
//{
//    super.title = title;
//    if(title && ![title isEqualToString:self.viewModel.title])
//    {
//        self.viewModel.title = title;
//    }
//}

- (void)bindViewModel
{
    if (self.title) {
        self.viewModel.title = self.title;
    }
    RAC(self, title) = RACObserve(self.viewModel, title);

}

- (void)pushViewControllerWithUrl:(NSString*)url
{
    if ([url hasPrefix:URL_MasterLoginRoot]) {
        if(![self doLogin]){
            return ;
        }
    }
    [self pushViewControllerWithUrl:url callback:nil];
}

- (void)pushViewControllerWithUrl:(NSString*)url callback:(ViewControlerCallback)callback
{
    
    if ([[MasterUrlManager shareMasterUrlManager] isPrivateUrlString:url]) {
        if (![UserClient sharedUserClient].rawLogin) {
            [self doLogin];
            return;
        }
    }
    UIViewController *vct = [self.urlManager viewControllerWithUrl:url];
//    vct.view.backgroundColor = [UIColor whiteColor];
    if ([vct isKindOfClass:[UINavigationController class]]) {
        [self presentViewController:vct animated:YES completion:^{
            
        }];
    }else{
        vct.callbackBlock = callback;
        [self.navigationController pushViewController:vct animated:YES];
    }
}

#pragma mark -- 公开方法

- (void)showLoadingFailView:(BOOL)show{
    if (self.loadingFailView.hidden == !show) {
        [self.view bringSubviewToFront:self.loadingFailView];
        self.loadingFailView.hidden = show;
    }
}
- (BOOL)doLogin
{
    BOOL isLogin =[UserClient sharedUserClient].rawLogin;
    if (!isLogin) {
        UIViewController *vc = [MasterUrlManager getViewControllerWithUrl:URL_MasterLoginRoot];
        [self presentViewController:vc animated:TRUE completion:^{
            
        }];
        return NO;
    }
    if(self.userClient.password.length !=4){
        [self hiddenHUDWithString:@"请先设置安全码" error:NO];
        UIStoryboard *story = [UIStoryboard storyboardWithName:@"Mine" bundle:[NSBundle mainBundle]];
        UIViewController *myView = [story instantiateViewControllerWithIdentifier:@"AlterSecurityCideViewController"];
        [self.navigationController pushViewController:myView animated:YES];
        return NO;
    }
//    BOOL canLocation  = [self canLocation];
    return YES;
    
}


- (void)showUserCenter:(id)sender{
    if([self doLogin]){
        [[SlideNavigationController sharedInstance] toggleLeftMenu];
        [[NSNotificationCenter defaultCenter] postNotificationName:@"RefurbishMyInfo" object:nil];
    }
}

- (void)showHelpImageView:(NSString*)imageName{
    //    dispatch_time_t time = dispatch_time(DISPATCH_TIME_NOW, (Int64)(2 * NSEC_PER_SEC));
    NSUserDefaults* userDefaults = [NSUserDefaults standardUserDefaults];
//    [userDefaults removeObjectForKey:imageName];
    if (![userDefaults stringForKey:imageName]) {
        [userDefaults setObject:imageName forKey:imageName];
        [userDefaults synchronize];
        __block UIImageView *imageView = [[UIImageView alloc] init];
        imageView.contentMode = UIViewContentModeScaleAspectFit;
        imageView.image = [UIImage imageNamed:imageName];
        imageView.frame = CGRectMake(0, 0, ScreenWidth, ScreenHeight);
        [SharedAppDelegate.window addSubview:imageView];
        [imageView setTapActionWithBlock:^(UIGestureRecognizer *gestureRecoginzer) {
            [gestureRecoginzer.view removeFromSuperview];
        }];
    }
}
#pragma mark -- 下拉上拉刷新


- (void)addHeaderAndFooterViews:(UIScrollView*)scrollView
{
    scrollView.mj_header = [MasterTableHeaderView headerWithRefreshingTarget:self refreshingAction:@selector(headerFresh)];
    scrollView.mj_footer = [MasterTableFooterView footerWithRefreshingTarget:self refreshingAction:@selector(footerFresh)];
    self.freshScrollView = scrollView;
}
- (void)addHeaderView:(UIScrollView*)scrollView{
    scrollView.mj_header = [MasterTableHeaderView headerWithRefreshingTarget:self refreshingAction:@selector(headerFresh)];
    self.freshScrollView = scrollView;
}
- (void)addFooterView:(UIScrollView*)scrollView
{
    scrollView.mj_footer = [MasterTableFooterView footerWithRefreshingTarget:self refreshingAction:@selector(footerFresh)];
    self.freshScrollView = scrollView;
}

- (void)headerFresh{
    // 2.模拟2秒后刷新表格UI（真实开发中，可以移除这段gcd代码）
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        // 拿到当前的下拉刷新控件，结束刷新状态
        [self.freshScrollView.mj_header endRefreshing];
    });
}

- (void)footerFresh{
    // 2.模拟2秒后刷新表格UI（真实开发中，可以移除这段gcd代码）
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        // 拿到当前的下拉刷新控件，结束刷新状态
        [self.freshScrollView.mj_footer endRefreshing];
    });
}


- (void)showPhonesActionSheet
{
    UIActionSheet* actionSheet = [[UIActionSheet alloc] init];
    actionSheet.title = @"联系110";
    [actionSheet addButtonWithTitle:@"取消"];
    [actionSheet addButtonWithTitle:@"拨打110"];
    [actionSheet addButtonWithTitle:@"短信联系110"];
    [actionSheet setCancelButtonIndex:0];
    [actionSheet showInView:self.view];
    @weakify(self)
    [actionSheet.rac_buttonClickedSignal subscribeNext:^(NSNumber *index) {
        @strongify(self)
        switch ([index integerValue]) {
            case 1:
                [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"tel://%@",@"110"]]];
                break;
            case 2:
                [self showMessageView:@[@"12110"] title:@"短信110" body:@""];
        }
    }];
}
- (void)callPhonesActionSheet:(NSString*)phones
{
    NSString* courseMobile = phones;
    courseMobile = [courseMobile stringByReplacingOccurrencesOfString:@"、" withString:@","];
    courseMobile = [courseMobile stringByReplacingOccurrencesOfString:@"，" withString:@","];
    NSArray* phonesArray = [courseMobile componentsSeparatedByString:@","];
    UIActionSheet* actionSheet = [[UIActionSheet alloc] init];
    actionSheet.title = @"电话号码";
    [actionSheet addButtonWithTitle:@"取消"];
    for (NSString* phone in phonesArray) {
        [actionSheet addButtonWithTitle:phone];
    }
    [actionSheet setCancelButtonIndex:0];
    [actionSheet showInView:self.view];
    @weakify(actionSheet)
    [actionSheet.rac_buttonClickedSignal subscribeNext:^(NSNumber *index) {
        @strongify(actionSheet)
        if (index.integerValue>0) {
            NSString* phone = [actionSheet buttonTitleAtIndex:index.integerValue];
            [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"tel://%@",phone]]];
        }
    } ];
}

- (void)showRequestErrorMessage:(BaseModel*)model
{
    if (model.code!=200) {
        if (model.alert && ![model.alert[@"msg"] isEmpty]) {
            self.requestAlert = model.alert;
            [self showAlertMessage];
        }else{
            [self hiddenHUDWithString:model.message error:YES];
        }
    }
}

- (void)showAlertMessage{
    NSString *title = self.requestAlert[@"title"];
    NSString *message = self.requestAlert[@"msg"];
    NSString *url = self.requestAlert[@"url"];
    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:title message:message delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil];
    if (url && ![url isEmpty]) {
        alertView = [[UIAlertView alloc] initWithTitle:title message:message delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:@"取消",nil];
        @weakify(self);
        [alertView.rac_buttonClickedSignal subscribeNext:^(NSNumber *index) {
            @strongify(self);
            if (index.integerValue==0) {
                [self pushViewControllerWithUrl:self.requestAlert[@"url"]];
            }
        } ];
    }
    [alertView show];
}
-(void) setmobileText:(NSString *)mobile AndNameText:(NSString *)name{
    [self showMessageView:@[mobile] title:name body:self.message];
}
#pragma 短信
-(void)showMessageView:(NSArray *)phones title:(NSString *)title body:(NSString *)body
{
    if( [MFMessageComposeViewController canSendText] )
    {
        MFMessageComposeViewController * controller = [[MFMessageComposeViewController alloc] init];
        controller.recipients = phones;
        controller.navigationBar.tintColor = [UIColor redColor];
        controller.body = body;
        controller.messageComposeDelegate = self;
        [self presentViewController:controller animated:YES completion:nil];
        [[[[controller viewControllers] lastObject] navigationItem] setTitle:title];//修改短信界面标题
    }
    else
    {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示信息"
                                                        message:@"该设备不支持短信功能"
                                                       delegate:nil
                                              cancelButtonTitle:@"确定"
                                              otherButtonTitles:nil, nil];
        [alert show];
    }
}
-(void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result
{
    [self dismissViewControllerAnimated:YES completion:nil];
    switch (result) {
        case MessageComposeResultSent:
            [self hiddenHUDWithString:@"发送成功" error:NO];
            
            break;
        case MessageComposeResultFailed:
            //信息传送失败
            
            break;
        case MessageComposeResultCancelled:
            //信息被用户取消传送
            
            break;
        default:
            break;
    }
}
-(void) sendMessageToSb:(id)sbInfo bytype:(NSInteger )type{
    NSArray* nibView =  [[NSBundle mainBundle] loadNibNamed:@"SendMessageView" owner:nil options:nil];
    self.sendMessageView =[nibView objectAtIndex:0];
    self.sendMessageView .alpha=0.0f;
    self.sendMessageView.frame = CGRectMake(0, 0, ScreenWidth, ScreenHeight-64);
    [self.view addSubview:self.sendMessageView];
    [UIView animateWithDuration:0.4 animations:^{
        self.sendMessageView .alpha=1.0f;
    } completion:^(BOOL finish){
        self.sendMessageView.delegate =self;
        self.sendMessageView.commendType =type;
        self.sendMessageView.sbInfo =sbInfo;
    }];
}

-(void) addShareDataViewToSbWithShareData:(id)shareData{
    self.navigationController.navigationBar.userInteractionEnabled = NO;
    NSArray* nibView =  [[NSBundle mainBundle] loadNibNamed:@"ShareData" owner:nil options:nil];
    self.shareDataView  = [nibView objectAtIndex:0];
    self.shareDataView  .alpha=0;
    self.shareDataView.frame = CGRectMake(0, 0, ScreenWidth, ScreenHeight);
    //[self suspendWindowWithItem:self.shareDataView];
    [self.view addSubview:self.shareDataView];
    @weakify(self)
    [UIView animateWithDuration:0.4 animations:^{
        self.shareDataView .alpha=1.0f;
    } completion:^(BOOL finish){
        @strongify(self)
        self.shareDataView.shareData = shareData;
        self.shareDataView.shareDataDelegate = self;
    }];
}

//隐藏导航栏最底下的线条
//- (UIImageView *)findHairlineImageViewUnder:(UIView *)view {
//    if ([view isKindOfClass:UIImageView.class] && view.bounds.size.height <= 1.0) {
//        return (UIImageView *)view;
//    }
//    for (UIView *subview in view.subviews) {
//        UIImageView *imageView = [self findHairlineImageViewUnder:subview];
//        if (imageView) {
//            return imageView;
//        }
//    }
//    return nil;
//}
-(void)textFiledEditChanged:(NSNotification *)obj{
    UITextField *textField = (UITextField *)obj.object;
    NSInteger kMaxLength = 5;
    NSString *toBeString = textField.text;
    NSString *lang = [[UITextInputMode currentInputMode] primaryLanguage]; // 键盘输入模式
    if ([lang isEqualToString:@"zh-Hans"]) { // 简体中文输入，包括简体拼音，健体五笔，简体手写
        UITextRange *selectedRange = [textField markedTextRange];
        //获取高亮部分
        UITextPosition *position = [textField positionFromPosition:selectedRange.start offset:0];
        // 没有高亮选择的字，则对已输入的文字进行字数统计和限制
        if (!position) {
            if (toBeString.length > kMaxLength) {
                [self hiddenHUDWithString:@"最多输入5字符" error:NO];
                textField.text = [toBeString substringToIndex:kMaxLength];
            }
        }
        // 有高亮选择的字符串，则暂不对文字进行统计和限制
        else{
            
        }
    }
    // 中文输入法以外的直接对其统计限制即可，不考虑其他语种情况
    else{
        if (toBeString.length > kMaxLength) {
            [self hiddenHUDWithString:@"最多输入5字符" error:NO];
            textField.text = [toBeString substringToIndex:kMaxLength];
        }
    }
    if(textField.text.length ==5){
       
    }

}

- (void)addUserBehaviourString:(NSString*)str{
//    NSDate* dat = [NSDate dateWithTimeIntervalSinceNow:0];
    NSTimeInterval a=[[NSDate date] timeIntervalSince1970]*1000;
    NSString *timeString = [[[NSString stringWithFormat:@"%f", a] componentsSeparatedByString:@"."] firstObject];
    NSString *tempStr = [NSString stringWithFormat:@"#%@_%@",str,timeString];
    NSString *userBehaviourString = nil;
    if ([[NSUserDefaults standardUserDefaults] objectForKey:UserBehaviourKey] != nil) {
        userBehaviourString = [[[NSUserDefaults standardUserDefaults] objectForKey:UserBehaviourKey] stringByAppendingString:tempStr];
        [[NSUserDefaults standardUserDefaults] setObject:userBehaviourString forKey:UserBehaviourKey];
    }else{
        [[NSUserDefaults standardUserDefaults] setObject:tempStr forKey:UserBehaviourKey];
    }
    NSLog(@"%@",[[NSUserDefaults standardUserDefaults] objectForKey:UserBehaviourKey]);
}
#pragma mask -- UIGestureRecognizerDelegate

- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer;
{
    return [self canGotoBack];
}
- (void)dealloc
{
    NSLog(@"dealloc  ===============================%@",self);
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
